package com.aramis.mydytt.ui.base

import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.aramis.mydytt.widget.LoadingStateView

/**
 * Description: BaseFragment
 * @author lizhidan
 * Created: 2021/4/7
 */
open class BaseFragment : Fragment() {

    inline fun <reified R : ViewModel> createViewModel(): R {
        return ViewModelProvider(this).get(R::class.java)
    }

    fun LoadingStateView.showState(data: List<*>?) {
        when {
            data == null -> showError()
            data.isEmpty() -> showEmpty()
            else -> dismiss()
        }
    }
}